<?php
/*
Template Name: Template Homesite
*/
?>
<?php get_header(); ?>

<div id="content">

    <div id="inner-content" class="wrap clearfix">

        <div id="main" class="eightcol first clearfix" role="main">

            <ul>
                <?php
                $upload = wp_upload_dir();
                $pages = query_posts("post_type=page&post_status=publish&posts_per_page=9999&orderby=menu_order&order=ASC");
                $i = 1;
                foreach($pages as $page) {
                    //echo $page->ID . "<br/> ";
                    if($page->post_parent == 0){
                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'single-post-thumbnail' );
                        $pageTitle = $page->post_title;

                        if($pageTitle == "Über Uns"){
                            $output = '<li class="sub" id="UeberUns">';
                        } else {
                            $output = '<li class="sub" id="' . $pageTitle .'">';
                        }

                        if(!empty($image[0]))$output .= '<img class="full" src="' . $image[0] . '" alt="' . $pageTitle . '">';
                        if($pageTitle == "Kontakt" || $pageTitle == "Impressum") {
                            $output .= '<article class="text-box rechts">';
                        } else {
                            if($pageTitle == "Leistungen" || $pageTitle == "Referenzen" || $pageTitle == "Team"){
                                $output .= '<article>';
                            } else {
                                $output .= '<article class="text-box links">';
                            }
                        }
                        if($pageTitle != "Home"){
                            if($pageTitle != "Leistungen"){
                                if($pageTitle != "Referenzen"){
                                    if($pageTitle != "Team"){
                                        $output .= '<h1>' . $pageTitle . '</h1>';
                                    }
                                }
                            }
                        }
                        if($pageTitle == "Leistungen"){
                            $output .= getLeistungen();
                        } elseif ($pageTitle == "Team"){
                            $output .= getTeam();
                        } else {
                            $output .= '<div class="text">'.$page->post_content.'</div>';
                        }
                        $output .= '</article>';

                        if(has_children($page->ID)){
                            $output .= '<ul>';
                            $subpages = get_pages("child_of=$page->ID");
                            foreach($subpages as $subpage){

                                $image2 = wp_get_attachment_image_src( get_post_thumbnail_id( $subpage->ID ), 'single-post-thumbnail' );
                                $output .= '<li class="sub-child" id="' . $subpage->post_title .'">';
                                if(!empty($image2[0]))$output .= '<img class="full" src="' . $image2[0] . '" alt="' . $page->post_title . '>';
                                $output .= '<article class="text-box">';
                                $output .= '<h1>' . $subpage->post_title . '</h1>';
                                $output .= '<div>'.$subpage->post_content.'</div>';;
                                $output .= '</article>';
                            }
                            $output .= '</ul>';
                        }
                        $output .= '</li>';

                        echo $output;
                    }
                    $i++;
                }
                echo '<div style="display:none" id="hilfe">'.$i.'</div>';

                function has_children($post_id) {
                    $children = get_pages("child_of=$post_id");
                    if( count( $children ) != 0 ) { return true; } // Has Children
                    else { return false; } // No children
                }

                function getLeistungen(){
                    $upload = wp_upload_dir();
                    $postsLesitungenInnen = get_posts( 'cat=5&tag=Innen' );
                    $content = '<div id="Innen" style="width: 50%; border-right: 5px solid #FFF; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; float: left;">';
                    $content .= '<img class="fullL" src='.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_03.jpg' .' alt="" />';
                    $content .= '<div id="listA" class="alpha60" style="padding: 15px; width: 24%; height: 65%; overflow-y: scroll; position: absolute; top:5%; left: 5%; background-image: url('.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_03.png'.') ; background-position: 100% 100%; background-repeat: no-repeat;">';
                            foreach($postsLesitungenInnen as $innen){
                                $content .= '<a>' . $innen->post_title . '</a>';
                                $content .= '<div><p>' . $innen->post_content . '</p></div>';
                            }
                        $content .= '</div>';
                    //$content .= '<div style="margin: 0; position: relative; bottom: 0px; right: 0px; left: auto;"><img src='.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_03.png' .' alt=""/></div>';
                    $content .= '</div>';

                    $postsLesitungenGarten = get_posts( 'cat=5&tag=Garten' );
                    $content .= '<div id="Garten" style="width: 50%; border-left: 5px solid #FFF; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; float: right;">';
                    $content .= '<img class="fullL" src='.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_05.jpg' .' alt="" />';
                    $content .= '<div id="listB" class="alpha60 rechts" style="padding: 15px; width: 24%; height: 65%; position: absolute; overflow-y: scroll; top:5%; right: 5%; background-image: url('.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_06.png'.') ; background-position: 0% 100%; background-repeat: no-repeat;">';
                    foreach($postsLesitungenGarten as $garten){
                        $content .= '<a>' . $garten->post_title . '</a>';
                        $content .= '<div><p>' . $garten->post_content . '</p></div>';
                    }
                    //$content .= '<div style="margin: 0; position: absolute; bottom: -52px; right: 0px; left: auto;"><img src='.$upload["baseurl"] .'/2012/11/4-Leistungen_Layout_06.png' .' alt=""/></div>';
                    $content .= '</div>';
                    $content .= '</div>';

                    return $content;
                }

                function getReferenzen(){
                    $postsReferenzen = get_posts( 'cat=8' );

                    $i = 2;
                    $content = '<div id="images" style="width: 80%; margin-left: 10%; height: 65%; overflow-y: auto; position: absolute;">';
                    foreach($postsReferenzen as $ref){
                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $ref->ID ), 'single-post-thumbnail' );
                        $content .= '<div style="position: relative; margin-left: 5%; margin-bottom: 2%; float: left; margin-right: 5%; width: 25%; height: 15%;">';
                            $content .= '<img src="' . $image[0] . '" alt="" class="refImage">';
                        $content .= '</div>';
                        $content .= '<div style="position: relative; margin-left: 5%; margin-bottom: 2%; float: left; width: 50%; height: 15%; overflow-y: auto;">';
                            $content .= '<p>'.$ref->post_content.'</p>';
                        $content .= '</div><div style="clear: both"></div>';
                    }
                    $content .= '</div>';
                    return $content;
                }

                function getTeam(){
                    $postsTeam = get_posts( 'cat=9' );
                    $postsTeam = array_reverse($postsTeam);
                    $elemWidth = 100 / count($postsTeam);
                    $content = '';
                    $i = 0;
                    foreach($postsTeam as $team){
                        $titleLeft = ($i*33)+3;
                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $team->ID ), 'single-post-thumbnail' );
                        if(count($postsTeam) != $i) {
                            $content .= '<div class="contTeam" style="width:'.$elemWidth.'%; border-right: 5px solid #FFF; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; float: left;">';
                        } else {
                            $content .= '<div class="contTeam" style="width: '.$elemWidth.'%; float: left;">';
                        }
                        $content .= '<img class="imageTeam" src="' . $image[0] . '" alt=""/>';
                        $content .= '<div style="color: #FFF; font-size: 26px; text-align: center; width: 25%; position: absolute; top: 3%; left: '.$titleLeft.'%;">'.$team->post_title.'</div>';
                        $content .= '<div style="color: #FFF; font-size: 26px; text-align: center; width: 25%; text-decortation: none; position: absolute; bottom: 20%; left: '.$titleLeft.'%;">'.$team->post_content.'</div>';
                        $content .= '</div>';



                        $i++;
                    }



                    return $content;

                }

                ?>
            </ul>

        </div> <!-- end #main -->

    </div> <!-- end #inner-content -->

</div> <!-- end #content -->

<?php get_footer(); ?>
